package com.sailfish.springbootdemo.dao.db7;

import com.sailfish.springbootdemo.common.DB7TableName;
import com.sailfish.springbootdemo.pojo.db7.TbFlowCompVpl;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface TbFlowCompVplDao {
    @Insert("<script>" +
            "insert into " + DB7TableName.TB_FLOW_COMP_VPL + " " +
            "( "+
            "flow_no, " +
            "flow_level, " +
            "comp_code, " +
            "comp_type, " +
            "pkg_name, " +
            "assembly_type, " +
            "component_high_max_vpl, " +
            "component_high_max_pdm, " +
            "is_dense_comp, " +
            "stress_properties, " +
            "pin_high_max, " +
            "pin_high_min, " +
            "pastemask_thickness_max, " +
            "pastemask_thickness_min, " +
            "pth_diameter_min, " +
            "pin_min_pitch, " +
            "is_tht_power, " +
            "is_tht_capcitor, " +
            "is_glue, " +
            "is_little_retentionforce, " +
            "create_time, " +
            "create_user " +
            ")"+
            "values "+
            "<foreach collection=\"entities\" item=\"entity\" separator=\",\">" +
            "(" +
            "#{entity.flow_no}, " +
            "#{entity.flow_level}, " +
            "#{entity.comp_code}, " +
            "#{entity.comp_type}, " +
            "#{entity.pkg_name}, " +
            "#{entity.assembly_type}, " +
            "#{entity.component_high_max_vpl}, " +
            "#{entity.component_high_max_pdm}, " +
            "#{entity.is_dense_comp}, " +
            "#{entity.stress_properties}, " +
            "#{entity.pin_high_max}, " +
            "#{entity.pin_high_min}, " +
            "#{entity.pastemask_thickness_max}, " +
            "#{entity.pastemask_thickness_min}, " +
            "#{entity.pth_diameter_min}, " +
            "#{entity.pin_min_pitch}, " +
            "#{entity.is_tht_power}, " +
            "#{entity.is_tht_capcitor}, " +
            "#{entity.is_glue}, " +
            "#{entity.is_little_retentionforce}, " +
            "#{entity.create_time}, " +
            "#{entity.create_user}" +
            ")"+
            "</foreach>"+
            "</script>"
    )
    Integer insertTbFlowCompVplBatch(@Param("entities") List<TbFlowCompVpl> entities);


    @Update("<script>" +
            "update " + DB7TableName.TB_FLOW_COMP_VPL + " " +
            "set " +
            " <if test='entity.comp_type != null'>comp_type = #{entity.comp_type},</if>" +
            " <if test='entity.pkg_name != null'>pkg_name = #{entity.pkg_name},</if>" +
            " <if test='entity.assembly_type != null'>assembly_type = #{entity.assembly_type},</if>" +
            " <if test='entity.component_high_max_vpl != null'>component_high_max_vpl = #{entity.component_high_max_vpl},</if>" +
            " <if test='entity.component_high_max_pdm != null'>component_high_max_pdm = #{entity.component_high_max_pdm},</if>" +
            " <if test='entity.is_dense_comp != null'>is_dense_comp = #{entity.is_dense_comp},</if>" +
            " <if test='entity.stress_properties != null'>stress_properties = #{entity.stress_properties},</if>" +
            " <if test='entity.pin_high_max != null'>pin_high_max = #{entity.pin_high_max},</if>" +
            " <if test='entity.pin_high_min != null'>pin_high_min = #{entity.pin_high_min},</if>" +
            " <if test='entity.pastemask_thickness_max != null'>pastemask_thickness_max = #{entity.pastemask_thickness_max},</if>" +
            " <if test='entity.pastemask_thickness_min != null'>pastemask_thickness_min = #{entity.pastemask_thickness_min},</if>" +
            " <if test='entity.pth_diameter_min != null'>pth_diameter_min = #{entity.pth_diameter_min},</if>" +
            " <if test='entity.pin_min_pitch != null'>pin_min_pitch = #{entity.pin_min_pitch},</if>" +
            " <if test='entity.is_tht_power != null'>is_tht_power = #{entity.is_tht_power},</if>" +
            " <if test='entity.is_tht_capcitor != null'>is_tht_capcitor = #{entity.is_tht_capcitor},</if>" +
            " <if test='entity.is_glue != null'>is_glue = #{entity.is_glue},</if>" +
            " <if test='entity.is_little_retentionforce != null'>is_little_retentionforce = #{entity.is_little_retentionforce},</if>" +
            " update_time = #{entity.update_time}," +
            " update_user = #{entity.update_user}" +
            " where id = #{entity.id}" +
            //"where flow_no = #{entity.flow_no} and comp_code = #{entity.comp_code} and flow_level = #{entity.flow_level}" +
            "</script>"
    )
    Integer updateTbFlowCompVpl(@Param("entity") TbFlowCompVpl entity);

    @Update("<script>" +
            "update " + DB7TableName.TB_FLOW_COMP_VPL + " " +
            "set " +
            " <if test='entity.comp_type != null'>comp_type = #{entity.comp_type},</if>" +
            " <if test='entity.pkg_name != null'>pkg_name = #{entity.pkg_name},</if>" +
            " <if test='entity.assembly_type != null'>assembly_type = #{entity.assembly_type},</if>" +
            " <if test='entity.component_high_max_vpl != null'>component_high_max_vpl = #{entity.component_high_max_vpl},</if>" +
            " <if test='entity.component_high_max_pdm != null'>component_high_max_pdm = #{entity.component_high_max_pdm},</if>" +
            " <if test='entity.is_dense_comp != null'>is_dense_comp = #{entity.is_dense_comp},</if>" +
            " <if test='entity.stress_properties != null'>stress_properties = #{entity.stress_properties},</if>" +
            " <if test='entity.pin_high_max != null'>pin_high_max = #{entity.pin_high_max},</if>" +
            " <if test='entity.pin_high_min != null'>pin_high_min = #{entity.pin_high_min},</if>" +
            " <if test='entity.pastemask_thickness_max != null'>pastemask_thickness_max = #{entity.pastemask_thickness_max},</if>" +
            " <if test='entity.pastemask_thickness_min != null'>pastemask_thickness_min = #{entity.pastemask_thickness_min},</if>" +
            " <if test='entity.pth_diameter_min != null'>pth_diameter_min = #{entity.pth_diameter_min},</if>" +
            " <if test='entity.pin_min_pitch != null'>pin_min_pitch = #{entity.pin_min_pitch},</if>" +
            " <if test='entity.is_tht_power != null'>is_tht_power = #{entity.is_tht_power},</if>" +
            " <if test='entity.is_tht_capcitor != null'>is_tht_capcitor = #{entity.is_tht_capcitor},</if>" +
            " <if test='entity.is_glue != null'>is_glue = #{entity.is_glue},</if>" +
            " <if test='entity.is_little_retentionforce != null'>is_little_retentionforce = #{entity.is_little_retentionforce},</if>" +
            " update_time = #{entity.update_time}," +
            " update_user = #{entity.update_user}" +
            //" where id = #{entity.id}" +
            "where flow_no = #{entity.flow_no}  and flow_level = #{entity.flow_level}" +
            "</script>"
    )
    Integer updateTbFlowCompVplByFlowNo(@Param("entity") TbFlowCompVpl entity);


    @Delete("<script>" +
            "delete from " + DB7TableName.TB_FLOW_COMP_VPL + " " +
            "where id = #{id}" +
            "</script>"
    )
    Integer deleteTbFlowCompVpl(@Param("id") Integer id);

    @Delete("<script>" +
            "delete from " + DB7TableName.TB_FLOW_COMP_VPL + " " +
            "where flow_no = #{flow_no}" +
            "</script>"
    )
    Integer deleteTbFlowCompVplByFlowNo(@Param("flow_no") String flow_no);

    @Select("<script>" +
            "select " +
            " * "+
            "from " + DB7TableName.TB_FLOW_COMP_VPL + " " +
            "where flow_no = #{flowNo} and flow_level = #{flowLevel}" +
            "</script>"
    )
    List<TbFlowCompVpl> getTbFlowCompVplByFlowNo(@Param("flowNo") String flowNo,
                                           @Param("flowLevel") Integer flowLevel);

}
